﻿using System;
using System.Web;

namespace Daco.Web
{
    public class CPageContext : CBaseContext
    {
        private Daco.Web.UI.SitePage _currentPage = null;

        public Daco.Web.UI.SitePage CurrentPage
        {
            get { return _currentPage; }
            set { _currentPage = value; }
        }

        /// <summary>
        /// The _application.
        /// </summary>
        protected static HttpApplicationState _application = null;
        /// <summary>
        /// The _user.
        /// </summary>
        private Daco.Security.CMembershipUser _user = null;

        public static new CPageContext Current
        {
            get { return Daco.Pattern.CPageSingleton<CPageContext>.Instance; }
        }

        public static HttpContext Context
        {
            get { return HttpContext.Current ?? null; }
        }

        /// <summary>
        /// Get/set the current state of the Http Application.
        /// Defaults to HttpContext.Current.Application. If not available
        /// pulls from application variable.    
        /// </summary>
        public static HttpApplicationState Application
        {
            get
            {
                if (HttpContext.Current != null)
                {
                    return HttpContext.Current.Application;
                }

                return _application;
            }

            set
            {
                _application = value;
            }
        }

        /// <summary>
        /// Current Membership User
        /// </summary>
        public Daco.Security.CMembershipUser User
        {
            get
            {
                //if (this._user == null)
                //{
                //    this._user = new Daco.Security.CMembershipUser();
                //}

                return this._user;
            }

            set
            {
                this._user = value;
            }
        }
        #region IDisposable Members

        public override void Dispose()
        {
            base.Dispose();
        }

        #endregion
    }
}
